package com.cefa.edu.dao;


import com.cefa.edu.datasource.DataSource;
import com.cefa.edu.model.User;
import org.apache.ibatis.annotations.*;

import javax.websocket.server.PathParam;
import java.util.List;

@Mapper
public interface UserRoleMapper {
    @DataSource("cefaedu")
    @Select("select count(1) from cefa_edu_user WHERE user_name=#{userName}")
    int getUserByUserName(@Param("userName") String userName);

    @Select("select count(1) from cefa_edu_user_role WHERE user_id=#{userId} and role_id=#{roleId}")
    int getUserRole(@Param("userId") Integer userId,@Param("roleId") Integer roleId);

    @Select("select role_id from cefa_edu_user_role where user_id=#{userid}")
    List<Integer> getRoleIds(@PathParam("userid") Integer userid);

    @Select("select count(1) from cefa_edu_user u left join cefa_edu_user_education_level ul on u.id=ul.user_id where u.user_id=#{userId} and ul.level_id=#{levelId}")
    int  findUserBylevelId(@PathParam("userId") Integer userId,@PathParam("levelId") Integer levelId);


    @Select("select ur.id,u.school_id  from cefa_edu_user_role ur left join cefa_edu_role r on ur.role_id=r.id  where r.type=#{type} ")
    List<User> getUserRoleByType(@Param("type") Integer  type);
}
